package yawning.mew.cat;

import yawning.mew.ProcEffect;
import yawning.mew.ProcEffect.Effect;
import yawning.mew.Procs;
import yawning.mew.sim.SimulationEvent;

public class EventKirilProc extends SimulationEvent {
	CatModelSimState mState;
	private int mStacks;
	private int mStackAgi;
	private static int NR_STACKS_MAX = 10;

	EventKirilProc(CatModelSimState state) {
		super(state.mSimEngine);
		mState = state;
	}

	public void run(int itemId) {
		// Logging is handled in the upper level.

		// Note: The UI explicitly will prevent this so the check is somewhat superfluous.
		if (isUp()) throw new RuntimeException("Multiple instances of Kiril, Fury of the Beasts detected.");

		mStacks = 0;

		if (mStackAgi == 0) {
			ProcEffect proc = Procs.getInstance().getProcByItemID(itemId);
			mStackAgi = proc.get(Effect.AGILITY);
		}

		schedule(20, 1);
	}

	@Override
	public void onTick() {
		// XXX: I should optimize this to shave off the onTick() calls after the proc is fully ramped, but I don't care enough.
		if (mStacks < NR_STACKS_MAX) {
			mStacks++;
			mState.mModel.addAgility(mStackAgi);

			if (mState.mIsLogging) mState.mLog.log("Proc Tick: Kiril, Fury of the Beasts Stacks: %d\n", mStacks);
		}
	}

	@Override
	public void onExpire() {
		mState.mModel.addAgility(-mStackAgi * mStacks);
		mStacks = 0;
	}
}
